package com.tangruojie.controller;

import com.tangruojie.domain.Enterprise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("/books")
public class BookController {

    /**
     * 第一种获取配置文件的方式
     */
    @Value("${lesson}")
    private String lesson;

    @Value("${enterprise.name}")
    private String name;

    @Value("${enterprise.age}")
    private Integer age;

    @Value("${enterprise.tel}")
    private String tel;

    @Value("${enterprise.subjects[0]}")
    private String subjects;

    /**
     * 第二种获取配置文件的方式
     */
    @Autowired
    private Environment environment;

    /**
     * 第三种获取配置文件方式
     */
    @Autowired
    private Enterprise enterprise;

    @GetMapping("/{id}")
    public String getById(@PathVariable Integer id) {
        System.out.println("id:" + id);
        System.out.println("lesson:" + lesson);
        System.out.println("name:" + name);
        System.out.println("age:" + age);
        System.out.println("tel:" + tel);
        System.out.println("subjects:" + subjects);
        System.out.println("environment.getProperty(lesson):" + environment.getProperty("lesson"));
        System.out.println("environment.getProperty(enterprise.name):" + environment.getProperty("enterprise.name"));
        System.out.println(environment.getProperty("enterprise.subjects"));
        System.out.println(enterprise.getName());
        System.out.println(Arrays.toString(enterprise.getSubjects()));
        return "id:" + id;
    }

}
